<?php

/**
 * Class AjaxTool
 */
class AjaxTool
{

    /**
     * @param $code
     * @param $message
     * @param array $data
     */
    public static function returnJsonData($code, $message = '', $data = array())
    {
        header('content-type:application/json;charset=utf-8');
        $returnArr = array();
        $returnArr['code'] = isset($code) ? $code : 200;;
        $returnArr['message'] = $message ? $message : Setup_Error::getConfig($code);
        $returnArr['data'] = $data;
        echo json_encode($returnArr);
        exit();
    }

    /**
     * @param $code
     * @param string $message
     * @param array $data
     */
    public function _returnJSONP($code, $message = '', $data = [])
    {
        header('content-type:application/json;charset=utf-8');
        $callback = isset($_REQUEST['callback']) ? $_REQUEST['callback'] : "";
        $returnData = array(
            'code' => $code,
            'message' => $message,
            'data' => $data
        );
        $info = json_encode($returnData);
        echo $callback . '(' . $info . ')';
        exit;
    }
}